package com.inspur.his.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.inspur.his.pojo.Doct;
import com.inspur.his.pojo.DoctExt;
import com.inspur.his.pojo.User;
import com.inspur.his.service.DoctService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

//医生管理（老师例子）
@Controller
public class DoctorController {
    @Autowired
    DoctService doctService;

    @RequestMapping("doctListController")
    public String doctList(HttpServletRequest request, Model model, @RequestParam(value = "pn", defaultValue = "1") Integer pn){
        //获取页面提交来的查询条件
        String realname = request.getParameter("realname");
        String departid = request.getParameter("departid");
        //  点击用户管理左侧菜单进行默认无条件查询
        HashMap map = new HashMap();
        map.put("realname",realname);
        map.put("departid",departid);
        PageHelper.startPage(pn,5);
        List<DoctExt> doctList = doctService.doctList(map);
        PageInfo<DoctExt> pageInfo = new PageInfo<DoctExt>(doctList,doctList.size());
        model.addAttribute("doctList",doctList);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("realname",realname);
        model.addAttribute("departid",departid);
        return "doct/doctList.jsp";
    }
    @RequestMapping("/doctModifyController")
    public String modifyUser(String docId, Model model) {
        Doct doct = doctService.getDoctorById(docId);
        model.addAttribute("doctor", doct);
        return "doct/doctModify.jsp";
    }

    @RequestMapping("docList")
    @ResponseBody
    public List<DoctExt> docList(HttpServletRequest req){
        HashMap map = new HashMap<String, String>();
        String departid = req.getParameter("departid");
        map.put("departid", departid);
        String doctId = req.getParameter("doctId");
        map.put("doctId", doctId);
        List<DoctExt> docList =doctService.doctList(map);
        return docList;
    }
}
